package com.cskaoyan.demo6.service;

import com.cskaoyan.demo6.bean.model.MarketGoods;
import com.cskaoyan.demo6.bean.model.MarketGoodsExample;
import com.cskaoyan.demo6.bean.model.MarketTopic;
import com.cskaoyan.demo6.bean.model.MarketTopicExample;
import com.cskaoyan.demo6.bean.vo.HomeIndexVo;
import com.cskaoyan.demo6.mapper.MarketTopicMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description：
 * @Author：BLUEBLANK
 * @Date：2024/4/21 17:10
 */

@Service("topicService")
public class TopicServiceImpl implements TopicService {
    @Autowired
    MarketTopicMapper marketTopicMapper;
    @Override
    public List<HomeIndexVo.TopicListDTO> queryList(Integer offset, Integer topicLimit) {
        PageHelper.offsetPage(offset, topicLimit);

        MarketTopicExample example = new MarketTopicExample();
        MarketTopicExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);
        example.setOrderByClause("add_time desc");

        List<MarketTopic> marketTopics = marketTopicMapper.selectByExample(example);


        List<HomeIndexVo.TopicListDTO> topicList = new ArrayList<>();
        marketTopics.forEach(item -> {
            HomeIndexVo.TopicListDTO topicListDTO = new HomeIndexVo.TopicListDTO();
            BeanUtils.copyProperties(item, topicListDTO);
            topicList.add(topicListDTO);
        });
        return topicList;
    }
}
